package cn.tedu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.entity.User;
import cn.tedu.service.UserService;
import cn.tedu.service.impl.UserServiceImpl;
import cn.tedu.util.CommonValue;

/**
 * Servlet implementation class UserFindByIdServlet
 */
public class UserFindByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserFindByIdServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.获取提交的数据
		String uid=request.getParameter("id");
		int id=Integer.parseInt(uid);
		
		//2.调用根据id查询用户信息业务
		UserService userService=new UserServiceImpl();
		User user=userService.findUserById(id);
		System.out.println(user);
		//3.根据业务的结果做跳转
		//把User对象中的数据    "转发"   到userupdate.jsp中
		//a.绑定数据user到request对象中
		request.setAttribute("user", user);
		//b.转发request对象的数据到userupdate.jsp中
		request.getRequestDispatcher("userupdate.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
